package com.snpic.appaw.module.third.service.common;

import com.snpic.appaw.module.third.dal.dataobject.common.ThirdPartyFlowRecord;
import com.snpic.appaw.module.third.dal.mysql.common.ThirdPartyFlowRecordMapper;
import jakarta.annotation.Resource;
import jakarta.annotation.Resources;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author JiJun
 * @date 2025/9/4 9:28
 * @修改时间 2025/9/4 9:28
 * @description 第三方接口，记录服务实现类
 */
@Service
@Slf4j
public class ThirdPartyFlowRecordServiceImpl implements ThirdPartyFlowRecordService {
	@Resource
	private ThirdPartyFlowRecordMapper thirdPartyFlowRecordMapper;

	/**
	 * 记录请求流水
	 *
	 * @param record
	 */
	@Override
	public Long record(ThirdPartyFlowRecord record) {
		// 1. 设置默认值（如果前端没传）
		if (record.getRequestTime() == null) {
			record.setRequestTime(LocalDateTime.now());
		}
		thirdPartyFlowRecordMapper.insert(record);
		return record.getId();
	}

	/**
	 * 根据请求流水号查询请求流水
	 *
	 * @param recordId
	 * @return
	 */
	@Override
	public ThirdPartyFlowRecord getByRecordNo(String recordId) {
		return null;
	}

	/**
	 * 更新请求流水
	 *
	 * @param record
	 */
	@Override
	public void update(ThirdPartyFlowRecord record) {
		if (record == null || record.getId() == null) {
			log.error("更新参数异常: {}", record);
			throw new IllegalArgumentException("更新参数异常");
		}

		int updated = thirdPartyFlowRecordMapper.updateById(record);
		if (updated < 1) {
			log.warn("更新记录未生效，ID: {}", record.getId());
		}
		log.info("成功更新流水记录，ID: {}", record.getId());
	}

	/**
	 * 删除请求流水
	 *
	 * @param recordId
	 */
	@Override
	public void delete(String recordId) {

	}
}
